﻿package core.ui.controls
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;

    public class Window extends Sprite
    {
        public var ed:Tuyitu;
        public var title:TextField;
        public var drag:Sprite;
        public var maxme:IconButton;
        public var closeme:IconButton;
        private var tl:Bitmap;
        private var tm:Bitmap;
        private var tr:Bitmap;
        private var ml:Bitmap;
        private var mm:Bitmap;
        private var mr:Bitmap;
        private var bl:Bitmap;
        private var bm:Bitmap;
        private var br:Bitmap;

        public function Window(param1:Tuyitu, param2:String, param3:Boolean)
        {
            this.ed = param1;
            var _loc_4:* = new WindowBg();
            this.tl = new Bitmap(UI.GetPart(_loc_4, 0, 0, 24, 22));
            addChild(this.tl);
            this.tm = new Bitmap(UI.GetPart(_loc_4, 24, 0, 2, 22));
            addChild(this.tm);
            this.tr = new Bitmap(UI.GetPart(_loc_4, 26, 0, 24, 22));
            addChild(this.tr);
            this.ml = new Bitmap(UI.GetPart(_loc_4, 0, 22, 24, 41));
            addChild(this.ml);
            this.mm = new Bitmap(UI.GetPart(_loc_4, 24, 22, 2, 41));
            addChild(this.mm);
            this.mr = new Bitmap(UI.GetPart(_loc_4, 26, 22, 24, 41));
            addChild(this.mr);
            this.bl = new Bitmap(UI.GetPart(_loc_4, 0, 63, 24, 4));
            addChild(this.bl);
            this.bm = new Bitmap(UI.GetPart(_loc_4, 24, 63, 2, 4));
            addChild(this.bm);
            this.br = new Bitmap(UI.GetPart(_loc_4, 26, 63, 24, 4));
            addChild(this.br);
            _loc_4.dispose();
            _loc_4 = null;
            this.title = new TextField();
            this.title.defaultTextFormat = new TextFormat("Verdana,Helvetica,San-serif", 12, 16777215, false, false, false, null, null, "center");
            this.title.multiline = false;
            this.title.selectable = false;
            this.title.height = 18;
            this.title.y = 2;
            this.title.x = 8;
            this.title.text = param2;
            addChild(this.title);
            this.drag = new Sprite();
            this.drag.graphics.beginFill(9474192);
            this.drag.graphics.drawRect(0, 0, 100, 100);
            this.drag.graphics.endFill();
            this.drag.alpha = 0;
            this.drag.addEventListener(MouseEvent.MOUSE_DOWN, this.DragMouseDown, false, 0, true);
            this.drag.addEventListener(MouseEvent.MOUSE_UP, this.DragMouseUp, false, 0, true);
            addChild(this.drag);
            this.closeme = new IconButton(param1, "rm_close", new WinCloseOn());
            addChild(this.closeme);
            if (param3)
            {
                this.maxme = new IconButton(param1, "rm_max", new WinMaxOn());
                addChild(this.maxme);
            }
            return;
        }// end function

        public function DragMouseDown(event:MouseEvent) : void
        {
            this.startDrag(false, new Rectangle(-4000, 40, 8000, stage.stageHeight + 2000));
            this.ed.stage.addEventListener(MouseEvent.MOUSE_UP, this.DragMouseUp, true, 0, true);
            return;
        }// end function

        public function DragMouseUp(event:MouseEvent) : void
        {
            this.stopDrag();
            this.ed.stage.removeEventListener(MouseEvent.MOUSE_UP, this.DragMouseUp, true);
            return;
        }// end function

        public function SetTitle(IconButton:String) : void
        {
            this.title.text = IconButton;
            return;
        }// end function

        public function Resize(IconButton:int, IconButton:int, IconButton:Boolean = false) : void
        {
            if (IconButton < 270)
            {
                IconButton = 270;
            }
            if (IconButton < 170)
            {
                IconButton = 170;
            }
            var _loc_4:* = IconButton - 48;
            this.bm.width = IconButton - 48;
            var _loc_4:* = _loc_4;
            this.mm.width = _loc_4;
            this.tm.width = _loc_4;
            var _loc_4:* = IconButton - 26;
            this.mr.height = IconButton - 26;
            var _loc_4:* = _loc_4;
            this.mm.height = _loc_4;
            this.ml.height = _loc_4;
            var _loc_4:int = 24;
            this.bm.x = 24;
            var _loc_4:* = _loc_4;
            this.mm.x = _loc_4;
            this.tm.x = _loc_4;
            var _loc_4:* = this.tm.width + 24;
            this.br.x = this.tm.width + 24;
            var _loc_4:* = _loc_4;
            this.mr.x = _loc_4;
            this.tr.x = _loc_4;
            var _loc_4:int = 22;
            this.mr.y = 22;
            var _loc_4:* = _loc_4;
            this.mm.y = _loc_4;
            this.ml.y = _loc_4;
            var _loc_4:* = this.mm.height + 22;
            this.bl.y = this.mm.height + 22;
            var _loc_4:* = _loc_4;
            this.bm.y = _loc_4;
            this.br.y = _loc_4;
            this.title.width = IconButton - (this.maxme != null ? (50) : (30));
            this.drag.width = IconButton - 2;
            this.drag.height = 17;
            this.closeme.y = 4;
            this.closeme.x = IconButton - 21;
            if (this.maxme != null)
            {
                this.maxme.y = 4;
                this.maxme.x = IconButton - 39;
            }
            return;
        }// end function

        public function AddToStage(IconButton:Boolean = false) : void
        {
            if (this.ed != null)
            {
                this.x = int((this.ed.stage.stageWidth - this.width) / 2);
                this.y = int((this.ed.stage.stageHeight - this.height) / 2);
                this.ed.addChild(this);
                this.ed.SetModal(this, IconButton);
            }
            return;
        }// end function

    }
}
